package com.wangyadong.hobby.schedule.jobtask.dsa.lesson1;

import java.util.Arrays;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2019/1/818:32
 **/
public class InsertionExample2 {


    public static void main(String[] args) {
        Character[] chars = {23, 45, 12, 4, 'C', 'B', 'A'};
        Arrays.stream(sort(chars)).forEach(System.out::println);
    }

    public static Comparable[] sort(Comparable[] comparables) {
        int length = comparables.length;
        for (int i = 1; i < length; i++) {
            for (int j = i; j > 0 && comparables[j].compareTo(comparables[j - 1]) == -1; j--) {
                Comparable comparable = comparables[j];
                comparables[j] = comparables[j - 1];
                comparables[j - 1] = comparable;
            }
        }
        return comparables;
    }
}
